<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="__STATIC__/js/jquery.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <script type="text/javascript" src="__STATIC__/x-admin/js/xadmin.js"></script>
    <link rel="stylesheet" href="__STATIC__/x-admin/css/font.css">
    <link rel="stylesheet" href="__STATIC__/x-admin/css/xadmin.css">
    <link rel="stylesheet" href="__STATIC__/layui/css/layui.css">
</head>
<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="#">app</a>
        <a href="#">发现</a>
        <a href="#">运动游戏</a>
        <a href="#">添加游动游戏</a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:window.location.reload();" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div style="width: 500px;padding-top: 10px">
    <form class="layui-form" action="" name="" onsubmit="return false" id="add">
        <div class="layui-form-item">
            <label class="layui-form-label">标题</label>
            <div class="layui-input-block">
                <input type="text" name="title" placeholder="标题" lay-verify="title" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">内容</label>
            <div class="layui-input-block">
                <textarea name="contents" id="contents" placeholder="请输入内容" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
                <button onclick="window.history.go(-1);" class="layui-btn layui-btn-primary">返回</button>
            </div>
        </div>
    </form>
</div>
</body>
<script>
    layui.use(['upload','form','layedit'], function(){
        var form = layui.form;
        layedit = layui.layedit;
        index = layedit.build('contents',{
            tool: [
                'strong' //加粗
                ,'italic' //斜体
                ,'underline' //下划线
                ,'del' //删除线
                ,'left' //左对齐
                ,'center' //居中对齐
                ,'right' //右对齐
               // ,'image' //插入图片
            ]}
        );
        //建立编辑器
        layedit.getContent(index)
        form.verify({
            title: function(value){
                if(!value){
                    return '请输入标题';
                }
            },
        });
        form.on('submit(*)', function(data) {
            var content = layedit.getContent(index);
            var title = $("input[name=title]").val();
            $.ajax({
                type:'POST',
                url:'/app_explain/insert',
                data:{
                    title:title,
                    content:content,
                },
                success:function(res){
                    if(res.code){
                        layer.msg(res.msg,{icon:1,time:2000},function () {
                            window.location.reload();
                        });
                    }else{
                        layer.msg(res.msg,{icon:5,time:2000});
                    }
                }
            });
        });
    });
</script>
</html>